//
//  HYAboutUsViewController.m
//  XPlayer
//
//  Created by liguoqing on 2023/10/25.
//

#import "HYAboutUsViewController.h"
#import "HYAboutHeaderView.h"
#import <HYUIKit/HYWKWebViewController.h>

@interface HYAboutUsViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) UILabel *bottomLabel;

@end

@implementation HYAboutUsViewController

- (void)dealloc
{
    CLog(@"delloc -- %@",[self class]);
}

- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.navigationBarView.titleLabel.text = NSLocalizedString(@"关于我们",nil);
    [self configUI];
}

- (void)configUI
{
    self.view.backgroundColor = AppBgThemeColor;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.navigationBarView.mas_bottom);
        make.bottom.mas_equalTo(-50-HOME_BAR_HEIGHT);
    }];
    self.view.backgroundColor = AppContentBgThemeColor;
    [self.view addSubview:self.bottomLabel];
    [self.bottomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view).offset(-10-HOME_BAR_HEIGHT);
        make.left.mas_equalTo(30);
        make.right.mas_equalTo(-30);
        make.height.mas_equalTo(40);
    }];
}

#pragma mark - UITableViewDelegate & UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HYTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.backgroundColor = AppContentBgThemeColor;
    if(indexPath.row == 0){
        cell.textLabel.text = NSLocalizedString(@"用户协议", nil);
    }else{
        cell.textLabel.text = NSLocalizedString(@"隐私政策", nil);
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0){
        [self showUserAgreement];
    }else{
        [self showPrivacyAgreement];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kIsIPad?64:44;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    HYAboutHeaderView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"HYAboutHeaderView"];
    return headerView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return kIsIPad?200:140;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

#pragma mark - 用户协议
- (void)showUserAgreement
{
    HYWKWebViewController *vc = [[HYWKWebViewController alloc]init];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"UserAgreement" ofType:@"html" inDirectory:nil];
    vc.localUrl = filePath;
    vc.staticNavTitle = NSLocalizedString(@"用户协议", nil);
    [self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - 隐私协议
- (void)showPrivacyAgreement
{
    HYWKWebViewController *vc = [[HYWKWebViewController alloc]init];
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"PrivacyAgreement" ofType:@"html" inDirectory:nil];
    vc.localUrl = filePath;
    vc.staticNavTitle = NSLocalizedString(@"隐私政策", nil);
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark - loadLazy
- (UITableView *)tableView
{
    if(!_tableView){
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = AppBgThemeColor;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"HYTableViewCell"];
        [_tableView registerClass:[HYAboutHeaderView class] forHeaderFooterViewReuseIdentifier:@"HYAboutHeaderView"];
    }
    return _tableView;
}

- (UILabel *)bottomLabel
{
    if(!_bottomLabel){
        _bottomLabel = [[UILabel alloc]init];
        _bottomLabel.text = [NSString stringWithFormat:@"%@ %@",NSLocalizedString(@"当前版本", nil),[CommUtls getSoftShowVersion]];
        _bottomLabel.textColor = UIColor.systemGrayColor;
        _bottomLabel.font = FONT_SIZE(16);
        _bottomLabel.numberOfLines = 0;
        _bottomLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _bottomLabel;
}



@end
